#include "fig_boss_hummer.h"
#include "fighter.h"
#include "fig_bullet.h"
#include "fig_enemybullet_master.h"
#include "fig_player_craft.h"
#include "fig_boss_laser.h"
#include "fig_boss_attackmove_manager.h"


#include "math/intersection.h"
#include "num/rand.h"
#include "math/facing.h"
#include "dd/dd_man.h"


const float FIGBossHummer::LASER_SCALE_WITHOUT_GLOW = 0.4f;


FIGBossHummer::FIGBossHummer(FIGEnemyCraft::ENEMY_TYPES EnemyType) : 
										FIGEnemyBoss(EnemyType),
										m_pBossLaser(NULL)
{
	

	m_ShootCounter.SetLimit(6.5f);
	m_SecondaryWeaponCounter.SetLimit(8.0f);

	

	m_pBigGunLeft = m_Bone.GetBonePartByID(2);
	m_pBigGunRight = m_Bone.GetBonePartByID(3);
	
	m_Bone.GetBonePartByID(11)->SetShouldDraw(false);
	m_Bone.GetBonePartByID(12)->SetShouldDraw(false);	
	

}



void	FIGBossHummer::ReSpawn()
{
	FIGEnemyBoss::ReSpawn();
	m_ComeInStopY = 0.2f;

	if(!m_pBossLaser)
	{
		m_pBossLaser = new FIGBossLaser(this,
										m_Bone.GetBonePartByID(11),
										m_Bone.GetBonePartByID(12),
										LASER_SCALE_WITHOUT_GLOW,
										ColorfRGBA(1.0f,1.0f,1.0f,0.85f),
										1.0f
										);
	}
}

void	FIGBossHummer::Tick_Attack(float dt)
{
	//return;
	if(!m_IsAlive)
		return;
	FIGEnemyBoss::Tick_Attack(dt);
	
	if(FIGBossAttackMoveManager::Instance().ShouldDisableBoneMovement() == false)
	{
		if(m_pBigGunLeft)
			m_pBigGunLeft->AimToPlayer(m_Pos, 90.0f * dt );

		if(m_pBigGunRight)
			m_pBigGunRight->AimToPlayer(m_Pos, 90.0f * dt );



		if(m_pBossLaser)
			m_pBossLaser->Tick(	dt,
			m_Bone.GetPosByWayPoint(0)  ,
							m_Bone.GetPosByWayPoint(1)
							);
	}
	
}


void		FIGBossHummer::BigGunShoots()
{
	
	//return;
	const int SHOOT_COUNT = 5;

	for( int i = 0 ; i < SHOOT_COUNT; i++)
	{
		FIGEnemyBulletMaster::Instance().Shoot(this,
												m_Bone.GetPosByWayPoint(4), 
												FIGEnemyBulletMaster::BULLET_TYPE_LONG_RED,
												FIGBullet::SHOOT_STYLES_DOUBLE,
												m_pBigGunLeft->GetRotation(),
												0.5f * i,
												false,
												m_pBigGunRight,
												false,
												FIGSounds::BOSS_SHOOT
												);


		
		FIGEnemyBulletMaster::Instance().Shoot(this,
												m_Bone.GetPosByWayPoint(5), 
												FIGEnemyBulletMaster::BULLET_TYPE_LONG_RED,
												FIGBullet::SHOOT_STYLES_DOUBLE,
												m_pBigGunRight->GetRotation(),
												0.5f * i,
												false,
												m_pBigGunLeft,
												false,
												FIGSounds::BOSS_SHOOT
												);
	}



}



void	FIGBossHummer::OnShootStyle1()
{
	//return;
	float ExtraDegree = 0;

	if(m_Pos.y > FIGPlayerCraft::Instance().GetPos(). y)
		ExtraDegree = 180.0f;

	int Count = num::RAND32::Instance().RandInt(3,5);
	for(int i = 0; i < Count;i++)
	{
		
		FIGEnemyBulletMaster::Instance().Shoot(this,
												m_Bone.GetPosByWayPoint(2), 
												FIGEnemyBulletMaster::BULLET_TYPE_CIRCLE_GLOW,
												FIGBullet::SHOOT_STYLES_SINGLE,
												180 + ExtraDegree,
												1.0f * i,
												false,
												NULL,
												false,
												FIGSounds::BOSS_SHOOT
												);

		FIGEnemyBulletMaster::Instance().Shoot(this,
												m_Bone.GetPosByWayPoint(3), 
												FIGEnemyBulletMaster::BULLET_TYPE_CIRCLE_GLOW,
												FIGBullet::SHOOT_STYLES_SINGLE,
												180 + ExtraDegree,
												1.0f * i,
												false,
												NULL,
												false,
												FIGSounds::BOSS_SHOOT
												);

		//---------------------

		FIGEnemyBulletMaster::Instance().Shoot(this,
												m_Bone.GetPosByWayPoint(2), 
												FIGEnemyBulletMaster::BULLET_TYPE_CIRCLE_GLOW,
												FIGBullet::SHOOT_STYLES_SINGLE,
												-25 + 180 + ExtraDegree,
												1.0f * i,
												false,
												NULL,
												false,
												FIGSounds::BOSS_SHOOT
												);

		FIGEnemyBulletMaster::Instance().Shoot(this,
												m_Bone.GetPosByWayPoint(3), 
												FIGEnemyBulletMaster::BULLET_TYPE_CIRCLE_GLOW,
												FIGBullet::SHOOT_STYLES_SINGLE,
												-25 + 180 + ExtraDegree,
												1.0f * i,
												false,
												NULL,
												false,
												FIGSounds::BOSS_SHOOT
												);

		//------------------------------------

		FIGEnemyBulletMaster::Instance().Shoot(this,
												m_Bone.GetPosByWayPoint(2), 
												FIGEnemyBulletMaster::BULLET_TYPE_CIRCLE_GLOW,
												FIGBullet::SHOOT_STYLES_SINGLE,
												25 + 180 + ExtraDegree,
												1.0f * i,
												false,
												NULL,
												false,
												FIGSounds::BOSS_SHOOT
												);

		FIGEnemyBulletMaster::Instance().Shoot(this,
												m_Bone.GetPosByWayPoint(3), 
												FIGEnemyBulletMaster::BULLET_TYPE_CIRCLE_GLOW,
												FIGBullet::SHOOT_STYLES_SINGLE,
												25 + 180 + ExtraDegree,
												1.0f * i,
												false,
												NULL,
												false,
												FIGSounds::BOSS_SHOOT
												);
	}


	//------------------------------ TRIPPLE LAYER BULLET---------------
	int C = 8;
	float Delay = 0.0f;
	for(int i = 0; i < C; i++)
	{
		Delay += (0.1f); 
		FIGEnemyBulletMaster::Instance().Shoot(
											this,
											m_Bone.GetPosByWayPoint(2),
											FIGEnemyBulletMaster::BULLET_TYPE_CIRCLE_TRIPPLELAYER,
											FIGBullet::SHOOT_STYLES_DOUBLE,
											(360.0f / (float)C) * i ,		// degree
											Delay,
											false,
											NULL,
											false,
											FIGSounds::BOSS_SHOOT
          									);
	}

	Delay  = 0.0f;
	for(int i = 0; i < C; i++)
	{
		Delay += (0.1f); 
		FIGEnemyBulletMaster::Instance().Shoot(
											this,
											m_Bone.GetPosByWayPoint(3),
											FIGEnemyBulletMaster::BULLET_TYPE_CIRCLE_TRIPPLELAYER,
											FIGBullet::SHOOT_STYLES_DOUBLE,
											(360.0f / (float)C) * i ,		// degree
											Delay,
											false,
											NULL,
											false,
											FIGSounds::BOSS_SHOOT
          									);
	}

}

void	FIGBossHummer::OnShootStyle2()
{
	BigGunShoots();
}

void	FIGBossHummer::OnShootStyle3()
{
	//return;
	int Count = num::RAND32::Instance().RandInt(5,7);
	for(int i = 0; i < Count;i++)
	{
		
		if(i % 2 == 0)
			FIGEnemyBulletMaster::Instance().Shoot(this,
												m_Bone.GetPosByWayPoint(2), 
												FIGEnemyBulletMaster::BULLET_TYPE_CIRCLE_GLOW,
												FIGBullet::SHOOT_STYLES_RAMBO_5,
												0,
												1.0f * i,
												false,
												NULL,
												false,
												FIGSounds::BOSS_SHOOT
												);
		else
			FIGEnemyBulletMaster::Instance().Shoot(this,
												m_Bone.GetPosByWayPoint(3), 
												FIGEnemyBulletMaster::BULLET_TYPE_CIRCLE_GLOW,
												FIGBullet::SHOOT_STYLES_RAMBO_5,
												0,
												1.0f * i,
												false,
												NULL,
												false,
												FIGSounds::BOSS_SHOOT
												);
	}
}

void	FIGBossHummer::OnShootStyle4()
{
	BigGunShoots();
}

void	FIGBossHummer::OnSecondaryWeaponShoot()
{
	
	if(m_pBossLaser)
		m_pBossLaser->StartWarningAndShoot();
	
	
}


void	FIGBossHummer::Render(const math::Vec2& Offset,float Scale)
{
	FIGEnemyBoss::Render(Offset,Scale);

	if(m_BossState == BOSS_STATE_ATTACK)
	{
		// right laser
		if(m_pBossLaser)
			m_pBossLaser->Render(Offset,Scale);
	}


}

void		FIGBossHummer::RenderDebug(const math::Vec2& Offset,float Scale)
{
	FIGEnemyBoss::RenderDebug(Offset,Scale);

	if(m_BossState != BOSS_STATE_ATTACK)
		return;

	if(m_pBossLaser)
	m_pBossLaser->RenderDebug( Offset,Scale);
	
}



bool	FIGBossHummer::CanTransformBackAttack() const 
{ 
	if( m_pBossLaser &&  
		m_pBossLaser->GetState()  == FIGBossLaser::LASER_STATE_NONE)
		return true; 

	return false;
}

void	FIGBossHummer::OnDie()
{
	FIGEnemyBoss::OnDie();
	UTIL_SAFE_DELETE(m_pBossLaser);
}
